package com.reny.szkj.ft_home.ui.index

import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Route
import com.reny.ll.git.base_logic.MActivity
import com.reny.ll.git.base_logic.adapter.TabPagerAdapter
import com.reny.ll.git.base_logic.config.RConfig
import com.reny.ll.git.mvvm.extras.getRColor
import com.reny.ll.git.mvvm.extras.getRStringArr
import com.reny.szkj.ft_home.R
import com.reny.szkj.ft_home.databinding.ActivityMainBinding
import com.reny.szkj.ft_home.ui.index.home.HomeFragment
import com.reny.szkj.ft_home.widget.SpecialTab
import me.majiajie.pagerbottomtabstrip.NavigationController
import me.majiajie.pagerbottomtabstrip.item.BaseTabItem


@Route(path = RConfig.FtHome.main)
class MainActivity : MActivity<ActivityMainBinding>() {

    override val layoutId: Int = R.layout.activity_main

    override fun isTransStatusBar(): Boolean = true

    private lateinit var fragmentList: List<Fragment>

    var navController: NavigationController? = null

    override fun initView() {
        //router().build(RConfig.FtLogin.login).navigation()
        fragmentList = listOf(
            HomeFragment(),
            HomeFragment(),
            HomeFragment(),
            HomeFragment()
        )
        binding.vp.setCanScroll(false)
        binding.vp.offscreenPageLimit = fragmentList.size
        binding.vp.adapter = TabPagerAdapter(
            supportFragmentManager,
            fragmentList
        )

        val tabTitles = getRStringArr(R.array.tabTitles)
        navController = binding.pnvTab.custom()
            .addItem(newItem(R.mipmap.ic_tab_1_n, R.mipmap.ic_tab_1_p, tabTitles[0]))
            .addItem(newItem(R.mipmap.ic_tab_2_n, R.mipmap.ic_tab_2_p, tabTitles[1]))
            .addItem(newItem(R.mipmap.ic_tab_3_n, R.mipmap.ic_tab_3_p, tabTitles[2]))
            .addItem(newItem(R.mipmap.ic_tab_4_n, R.mipmap.ic_tab_4_p, tabTitles[3]))
            .build()
        navController?.setupWithViewPager(binding.vp)

        navController?.setSelect(0)
    }

    private fun newItem(
        drawable: Int,
        checkedDrawable: Int,
        text: String
    ): BaseTabItem {
        val mainTab = SpecialTab(this)
        mainTab.initialize(drawable, checkedDrawable, text)
        mainTab.setTextDefaultColor(getRColor(R.color.tab_txt_n))
        mainTab.setTextCheckedColor(getRColor(R.color.theme))
        return mainTab
    }

    override fun onBackPressed() {
        moveTaskToBack(false)
    }

}